package hongvt.quanlynhanvien.adapter;

import hongvt.quanlynhanvien.R;
import hongvt.quanlynhanvien.TabEmpActivity;
import hongvt.quanlynhanvien.R.id;
import hongvt.quanlynhanvien.R.layout;
import hongvt.quanlynhanvien.R.string;
import hongvt.quanlynhanvien.model.Timekeeping;

import java.util.List;

import android.content.ClipData.Item;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CustomAdapter extends BaseAdapter {
	Context context;
	List<Timekeeping> items;
	int daysQty;

	public CustomAdapter(Context context, List<Timekeeping> items, int daysQty) {
		this.context = context;
		this.items = items;
		this.daysQty = daysQty;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {

			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			convertView = inflater.inflate(
					R.layout.layout_emp_timekeeping_report, null, false);
		}

		Timekeeping p = getItem(position);

		TextView tt = (TextView) convertView.findViewById(R.id.cusAdap_Name);
		TextView tt1 = (TextView) convertView.findViewById(R.id.cusAdap_Yes);
		TextView tt3 = (TextView) convertView.findViewById(R.id.cusAdap_No);

		if (tt != null) {
			Log.i("name", p.getName());
			tt.setText(p.getName());
		}
		if (tt1 != null) {
			Log.i("quan", String.valueOf(p.getQuan()));
			tt1.setText(String.valueOf(p.getQuan()) + " "
					+ context.getResources().getString(R.string.ngay_di));
		}

		if (tt3 != null) {

			tt3.setText(String.valueOf(daysQty - p.getQuan())
					+ " "
					+ context.getResources().getString(R.string.ngay_nghi));
		}

		return convertView;
	}

	@Override
	public int getCount() {
		if (items != null) {
			return items.size();
		}

		return 0;
	}

	@Override
	public Timekeeping getItem(int position) {
		// TODO Auto-generated method stub
		return items.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}
}
